<?php

namespace App\Library\Logic;

use App\Models\AuctionCertificationModel;
use App\Models\ShopUserAddressModel;
use Illuminate\Database\Eloquent\Relations\HasOne;

class AuctionCertificationLogic extends AuctionCertificationModel
{
    public static function check(): bool
    {
        return self::query()->where([
            'user_id' => USERID,
            'status' => 1,
        ])->orderByDesc('id')->exists();
    }

    public static function findStatusByUserId()
    {
        return self::query()->where('user_id', USERID)->orderByDesc('id')->value('status');
    }

    public function refundAddress(): HasOne
    {
        return self::hasOne(ShopUserAddressModel::class, 'user_id', 'user_id')->where('ua_is_refund', 1);
    }
}
